<!--
 * @Author: zhangjingyu
 * @Date: 2020-11-04 19:43:11
 * @LastEditors: zhangjingyu
 * @LastEditTime: 2021-01-06 17:30:57
 * @Description: 口径成员
-->
<template>
<!-- 口径成员页面 -->
  <div>
    <el-row class="caliberMembers container">
      <el-col :span="24" class="content-left">
          <!-- 操作区域 -->
         <upper-template 
         @search = "searchForm.page=1,searchFunc()" 
          @clear= "searchForm.caliberProjectCode='',searchForm.caliberProjectName='',searchForm.moduleCode = ''">
           <!-- 操作按钮区 -->
           <template slot="buttonArea">
             <el-button type="normal"  @click="addFunc">新增</el-button>
            <el-button type="normal" @click="editFunc">编辑</el-button>
            <el-button type="normal" @click="deleteFunc">删除</el-button>
            <el-button type="normal" @click="configFun">口径定义</el-button>
           </template>
           <!-- 搜索区 -->
           <template slot="searchArea">
               <el-form
                    :model="searchForm"
                    ref="searchForm"
                    label-width="87px"
                    label-position="left"
                    size="mini"
                  >
                    <el-form-item label="方案编码：">
             
                      <el-input v-model="searchForm.caliberProjectCode"  maxlength="40" style="width:150px"></el-input>
                    </el-form-item>
                    <el-form-item label="方案名称：" prop="caliberProjectName">
                      <el-input v-model="searchForm.caliberProjectName"  maxlength="40" style="width:150px"></el-input>
                    </el-form-item>
                    <el-form-item label="所属模块：	" prop="moduleCode">
                      <el-select
                        v-model="searchForm.moduleCode"
                        placeholder="请选择"
                        style="width:150px"
                        clearable
                      >
                      <el-option v-for="item in moduleList"
                       :key="item.moduleCode"
                       :value="item.moduleCode"
                       :label="item.moduleName"
                       ></el-option>
                        
                      </el-select>
                    </el-form-item>
                  </el-form>
           </template>
           <!-- 显示隐藏区 -->
           <template slot="columnHide">
               <el-checkbox-group v-model="checkList">
                    <el-checkbox
                      v-for="item in textData"
                      :label="item.label"
                      :key="item.prop"
                      :disabled="item.hideDisable"
                    >{{item.label}}</el-checkbox>
                  </el-checkbox-group>
           </template>
          </upper-template>

        <el-table ref="multipleTable" :data="tableData" style="width: 100%"
        @row-click="multipleTableRowClick">
          <el-table-column width="55" type="selection" ></el-table-column>
          <el-table-column
            v-for="(item, key) in showData"
            :key="key"
            :prop="item.prop"
            :label="item.label"
            :show-overflow-tooltip="true"
            :render-header="item.render"
            :sortable="item.sortable"
            :formatter="item.formatter"
          ></el-table-column>
        </el-table>
        <pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="searchForm.page"
          :page-size="searchForm.size"
          @refresh = "searchFunc"
          :total="total"
        ></pagination>
      </el-col>
    </el-row>
    <el-dialog v-dialogDrag title="口径方案" :visible.sync="addOrEdit" width="514px" top="2%">
      <el-form
        :model="saveForm"
        ref="saveForm"
        label-width="130px"
        label-position="left"
        :rules="saveFormRules"
      >
        <el-form-item label="口径方案编码：" prop="caliberProjectCode">
          <el-input
            v-model="saveForm.caliberProjectCode"
            :disabled="saveFlg!=1"
            placeholder="请输入口径方案编码"
             maxlength="40"
          ></el-input>
        </el-form-item>
        <el-form-item label="口径方案名称：" prop="caliberProjectName">
          <el-input v-model="saveForm.caliberProjectName" 
            placeholder="请输入口径方案名称"  maxlength="40"
          ></el-input>
        </el-form-item>
        <el-form-item label="所属模块：" prop="moduleCode">
          <el-select v-model="saveForm.moduleCode" placeholder="请选择所属模块" style="width:100%">
             <el-option v-for="item in moduleList"
                       :key="item.moduleCode"
                       :value="item.moduleCode"
                       :label="item.moduleName"
                       ></el-option>
                        
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button  @click="saveFunc">确 定</el-button>
        <el-button @click="addOrEdit = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 口径定义弹窗 -->
    <el-dialog v-dialogDrag title="口径定义" :visible.sync="isConfigDialog" width="70%" class="configWin">
           <el-row :gutter="20">
            <el-col  :span="14">
           <upper-template @search = "searchFF.page=1,searchFFunc()"  :configIcon="false" @clear= "searchFF.caliberName='',searchFF.caliberCode=''">
           <!-- 操作按钮区 -->
           <template slot="buttonArea">
            <el-button  @click="addFuncInner">新增</el-button>
            <el-button  @click="editFuncInner">编辑</el-button>
            <el-button  @click="deleteFuncInner">删除</el-button>
           </template>
           <!-- 搜索区 -->
           <template slot="searchArea">
               <el-form
                    :model="searchFF"
                    ref="searchFF"
                    label-width="87px"
                    label-position="left"
                    size="mini"
                  >
                    <el-form-item label="口径编码：" prop="caliberCode">
                      <el-input v-model="searchFF.caliberCode"
                       placeholder="请输入口径编码" style="width:150px"  maxlength="40"></el-input>
                    </el-form-item>
                    <el-form-item label="口径名称：" prop="caliberName">
                      <el-input v-model="searchFF.caliberName" style="width:150px"  maxlength="40"></el-input>
                    </el-form-item>
                  </el-form>
           </template>
          </upper-template>
          <el-table
            ref="definitionTable"
            :data="definitionTableData"
            style="width: 100%"
            @row-click="rowClickForRule"
          >
            <el-table-column width="55" type="selection" ></el-table-column>
            <el-table-column
              v-for="(item, key) in definitionConfig"
              :key="key"
              :prop="item.prop"
              :label="item.label"
              :align="item.align"
              :show-overflow-tooltip="true"
              :render-header="item.render"
              :sortable="item.sortable"
              :formatter="item.formatter"
              header-align="left"
              :width="item.width"
            ></el-table-column>
          </el-table>
          <pagination
            @size-change="handleSizeChangeConf"
            @current-change="handleCurrentChangeConf"
            :current-page="searchFF.page"
            :page-size="searchFF.size"
            @refresh = "searchFFunc"
            :pager-count="5"
            :total="totalConf"
          ></pagination>
        </el-col>
        <el-col  :span="10" class="content-right">
          <el-row class="title">
            <span class="gun"></span>
            业务口径规则 - {{RTitle}}
          </el-row>
         
          <el-row>
            <!-- 业务口径规则表 -->
            <el-table :data="kjRuleTable">
              <el-table-column width="40">
                <template slot-scope="scope">
                  {{scope.$index==0?"":"或"}}
                </template>
              </el-table-column>
              <el-table-column align="left" label="规则明细" header-align="center">
                <template slot-scope="scope">
                  <el-row v-for="(item,i) in scope.row.caliberRuleTermList" :key="scope.$index+''+i">
                    <el-col :span="8">{{item.rullDictName}}</el-col>
                    <el-col :span="5" :style="'color:'+(item.conditionFlag=='in'?'#1677FF':'#FF8F1F')">{{item.conditionFlag=='in'?'包含':'不包含'}}</el-col>
                    <el-col :span="11"> {{item.rullValName}}</el-col>
                  </el-row>
                </template>
              </el-table-column>
              <el-table-column width="80" label="操作">
                <template slot-scope="scope" >
                  <i class="rowIcon el-icon-edit-outline" @click="editRuleData(scope.row)" style="margin-right:10px"></i>
                  <i class="rowIcon el-icon-delete" @click="deleteRuleData(scope.row)"></i>
                </template>
              </el-table-column>
            </el-table>
          </el-row>
           <el-row style="padding:10px 0 ">
            <el-button @click="addRuleData">新增</el-button>
          </el-row>
        </el-col>
      </el-row>
         <!-- 口径定义新增/编辑（左表）弹窗 -->
      <el-dialog v-dialogDrag width="35%" :title="(saveFlgInner==1?'添加':'修改')+'业务口径表信息'" :visible.sync="isScopeDialog" append-to-body>
          <el-form
        :model="saveFormInner"
        ref="saveFormInner"
        label-width="130px"
        label-position="left"
        :rules="saveFormInnerRules"
      >
        <el-form-item label="口径编码：" prop="caliberCode">
          <el-input
            v-model="saveFormInner.caliberCode"
            :disabled="saveFlgInner!=1"
            placeholder="请输入口径编码"
          ></el-input>
        </el-form-item>
        <el-form-item label="口径名称：" prop="caliberName">
          <el-input v-model="saveFormInner.caliberName" 
            placeholder="请输入口径名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="所属口径方案：" prop="caliberProjectCode">
          <el-select v-model="saveFormInner.caliberProjectCode"  style="width:100%" disabled>
             <el-option v-for="item in moduleList"
                       :key="item.moduleCode"
                       :value="item.moduleCode"
                       :label="item.moduleName"
                       ></el-option>
                        
          </el-select>
        </el-form-item>
      </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button  @click="saveFuncInner">确 定</el-button>
          <el-button @click="isScopeDialog = false">取 消</el-button>
        </div>
      </el-dialog>
        <!-- 口径定义规则（右表）弹窗 -->
      <el-dialog v-dialogDrag width="60%" title="口径定义规则" :visible.sync="ruleDefShow" append-to-body>
          <rule-def :dataList="ruleDefList"></rule-def>
        <div slot="footer" class="dialog-footer">
          <el-button  @click="saveRuleDefFunc">确 定</el-button>
          <el-button @click="ruleDefShow = false">取 消</el-button>
        </div>
      </el-dialog>
      <div slot="footer"></div>
    </el-dialog>
  </div>
</template>

<script>
import { systemManage,publicManage_pub } from "@/api/index";
import upperTemplate from "@/components/upperTemplate.vue"
import ruleDef from "./components/ruleDef"
import moment from 'moment'
export default {
  components:{upperTemplate,ruleDef},
  data() {
    return {
      saveFlg: 1,
      saveFlgInner:1,
      addOrEdit: false,
      isConfigDialog: false,
      serachMore: false, // 搜索条件显影
      isScopeDialog:false,// 口径定义表新增编辑弹窗
      ruleDefShow:false,// 口径定义规则复杂弹窗
      RTitle: "",
      configRow:{},// 口径方案行数据暂存
      ruleRow:{},// 口径定义表行数据点击暂存
      ruleSaveFlag:1,
      searchForm: {
        caliberProjectCode:"",
        caliberProjectName:"",
        moduleCode:"",
        page:1,
        size:15
      },
      total:1,
      searchFF: {
        caliberName: "",
        caliberCode: "",
        page:1,size:15
      },
      totalConf:1,
      // 所属模块字典list
      moduleList:[
    
      ],
      saveForm: {},
      saveFormInner:{},
      checkList: [],
      //   列属性字段配置 -
      textData: [
        { prop: "caliberProjectCode", label: "口径方案编码", align: "left" ,hideDisable:true},
        { prop: "caliberProjectName", label: "口径方案名称", align: "left" ,hideDisable:true},
        { prop: "moduleCode", label: "所属模块 ", align: "left" ,sortable:true,hideDisable:true,formatter:(row)=>this.$getLabel(row.moduleCode,this.moduleList,'moduleCode','moduleName')},
        { prop: "creator", label: "创建人", align: "left",formatter:(row)=>row.creator||"-"},
        { prop: "createdTm", label: "创建时间 ", align: "right",formatter:(row)=>row.createdTm?moment(row.createdTm).format('YYYY-MM-DD HH:mm:ss'):'-',},
        { prop: "modifier", label: "修改人 ", align: "left",formatter:(row)=>row.modifier||"-"},
        { prop: "modifiedTm", label: "修改时间 ", align: "right",formatter:(row)=>row.modifiedTm?moment(row.modifiedTm).format('YYYY-MM-DD HH:mm:ss'):'-', }
      ],
      textData1:[
        { prop: "caliberCode", label: "口径编码 ",hideDisable:true},
        { prop: "caliberName", label: "口径名称 ", hideDisable:true },
        { prop: "caliberProject.caliberProjectName", label: "口径方案 ", hideDisable:true },
      ],
      //   列属性字段配置 - 口径定义表
      definitionConfig: [
        { prop: "caliberCode", label: "口径编码 ", align: "left",sortable:true,width:100},
        { prop: "caliberName", label: "口径名称 ", align: "left" },
        { prop: "caliberProject.caliberProjectName", label: "口径方案 ", align: "left",},
      ],
      // 口径定义表弹窗右侧
      kjRuleTable:[
        {"creator":null,"createdTm":null,"modifier":null,"modifiedTm":null,"caliberRullCode":"VP_ALM_COA10003001","caliberRullName":null,"caliberCode":"10003","caliberProjectCode":"VP_ALM_COA","rullDictCode":null,"addFlag":null,"conditionFlag":null,"sql":" (  ( productCd in  ('0101','01010101','01010201','01010301','01010401','01010402','01010403','01010501','01010502','01010503','01010505','01010506','01010507','01010508','01010509','01010510','01010511','01010512','01010513','01010514','01010515','01010516','01010517','01010518','01010519','01010601','01010602','01010603','01010604','01010605','01010606','01010607','01010608','01010609','01010610','01010611','01010612','01010613','01010614','01010615','01010616','01010617','01010618','01010619','01010620','01010621','01010622','01010623','01010624','01010625','01010626','01010627','01010628','01010629','01010630','01010631','01010632','01010633','01010634','01010635','01010636','01010701','01010702','01010703','01010704','01010705','01010706','01010801','01011001','01011002','01011003','01011004','01011005','01011101','01011102','01011103','01011104')  ) and ( 001 in   ( 333 )   )  )","rullSeq":"001","caliberRuleTermList":[{"creator":null,"createdTm":null,"modifier":null,"modifiedTm":null,"rullTermCode":"CT20190619000002","caliberRullCode":"VP_ALM_COA10003001","caliberCode":"10003","caliberProjectCode":"VP_ALM_COA","rullDictCode":"productCd","rullDictName":"产品","addFlag":null,"conditionFlag":"in","rullValTree":"1","rullVal":"0101","rullValName":"对公贷款","rullAllVal":"0001","sql":" ( productCd in  ('0101','01010101','01010201','01010301','01010401','01010402','01010403','01010501','01010502','01010503','01010505','01010506','01010507','01010508','01010509','01010510','01010511','01010512','01010513','01010514','01010515','01010516','01010517','01010518','01010519','01010601','01010602','01010603','01010604','01010605','01010606','01010607','01010608','01010609','01010610','01010611','01010612','01010613','01010614','01010615','01010616','01010617','01010618','01010619','01010620','01010621','01010622','01010623','01010624','01010625','01010626','01010627','01010628','01010629','01010630','01010631','01010632','01010633','01010634','01010635','01010636','01010701','01010702','01010703','01010704','01010705','01010706','01010801','01011001','01011002','01011003','01011004','01011005','01011101','01011102','01011103','01011104')  ) ","termSeq":"1","rullDictVal":"('0101','01010101','01010201','01010301','01010401','01010402','01010403','01010501','01010502','01010503','01010505','01010506','01010507','01010508','01010509','01010510','01010511','01010512','01010513','01010514','01010515','01010516','01010517','01010518','01010519','01010601','01010602','01010603','01010604','01010605','01010606','01010607','01010608','01010609','01010610','01010611','01010612','01010613','01010614','01010615','01010616','01010617','01010618','01010619','01010620','01010621','01010622','01010623','01010624','01010625','01010626','01010627','01010628','01010629','01010630','01010631','01010632','01010633','01010634','01010635','01010636','01010701','01010702','01010703','01010704','01010705','01010706','01010801','01011001','01011002','01011003','01011004','01011005','01011101','01011102','01011103','01011104')"},{"creator":null,"createdTm":null,"modifier":null,"modifiedTm":null,"rullTermCode":"CT20190619000003","caliberRullCode":"VP_ALM_COA10003001","caliberCode":"10003","caliberProjectCode":"VP_ALM_COA","rullDictCode":"001","rullDictName":"利率类型","addFlag":"and","conditionFlag":"in","rullValTree":"2","rullVal":"333","rullValName":"333-固定利率","rullAllVal":"TR_ALM_001","sql":"and ( 001 in   ( 333 )   ) ","termSeq":"2","rullDictVal":" ( 333 ) "}]},{"creator":null,"createdTm":null,"modifier":null,"modifiedTm":null,"caliberRullCode":"VP_ALM_COA10003002","caliberRullName":null,"caliberCode":"10003","caliberProjectCode":"VP_ALM_COA","rullDictCode":null,"addFlag":"OR","conditionFlag":null,"sql":" (  ( productCd in   ( 01020112 )   )  )","rullSeq":"002","caliberRuleTermList":[{"creator":null,"createdTm":null,"modifier":null,"modifiedTm":null,"rullTermCode":"CT20190619000004","caliberRullCode":"VP_ALM_COA10003002","caliberCode":"10003","caliberProjectCode":"VP_ALM_COA","rullDictCode":"productCd","rullDictName":"产品","addFlag":null,"conditionFlag":"in","rullValTree":"2","rullVal":"01020112","rullValName":"01020112-宜信公司合作贷款","rullAllVal":"0001","sql":" ( productCd in   ( 01020112 )   ) ","termSeq":"1","rullDictVal":" ( 01020112 ) "}]},{"creator":null,"createdTm":null,"modifier":null,"modifiedTm":null,"caliberRullCode":"VP_ALM_COA10003003","caliberRullName":null,"caliberCode":"10003","caliberProjectCode":"VP_ALM_COA","rullDictCode":null,"addFlag":"OR","conditionFlag":null,"sql":" (  ( GeneralLedger in  ('130304','13030401','13030402')  )  )","rullSeq":"003","caliberRuleTermList":[{"creator":null,"createdTm":null,"modifier":null,"modifiedTm":null,"rullTermCode":"CT20190619000005","caliberRullCode":"VP_ALM_COA10003003","caliberCode":"10003","caliberProjectCode":"VP_ALM_COA","rullDictCode":"GeneralLedger","rullDictName":"科目","addFlag":null,"conditionFlag":"in","rullValTree":"1","rullVal":"130304","rullValName":"贷款-小企业信贷中心专项短期贷款","rullAllVal":"0003","sql":" ( GeneralLedger in  ('130304','13030401','13030402')  ) ","termSeq":"1","rullDictVal":"('130304','13030401','13030402')"}]}
      ],
      saveFormRules: {
        caliberProjectCode: [
          { required: true, message: "请输入口径方案编码", trigger: "blur" },
           {
            pattern: /^[0-9a-zA-Z_]{1,30}$/,
            message: "只能输入1-30位的英文字母、数字、下划线",
            trigger: "blur"
          },
          { validator: this.caliberProjectCodeValid, trigger: "blur" }
        ],
        caliberProjectName: [
          { required: true, message: "请输入口径方案名称", trigger: "blur" },
          {
            pattern: /^[\u4E00-\u9FA5A-Za-z0-9_]{1,40}$/,
            message: "只能输入1-40位的中文、英文字母、数字、下划线",
            trigger: "blur"
          },
        ],
        moduleCode: [
          { required: true, message: "请选择所属模块", trigger: "blur" }
        ]
      },
      saveFormInnerRules:{
         caliberCode: [
          { required: true, message: "请输入口径编码", trigger: "blur" },
          {
            pattern: /^[0-9a-zA-Z_]{1,30}$/,
            message: "只能输入1-30位的英文字母、数字、下划线",
            trigger: "blur"
          },
          { validator: this.caliberCodeValid, trigger: "blur" }
        ],
        caliberName: [
          { required: true, message: "请输入口径名称", trigger: "blur" }
        ],
        caliberProjectCode: [
          { required: true, message: "请选择所属方案", trigger: "blur" }
        ]
      },
      treeData: [],
      definitionTableData: [],
      tableData: [],
      // 行内编辑编辑弹窗表单绑定数据
      ruleDefList: [],
      // 规则项新增编辑暂存
      addOrEditRuleRow:{}
    };
  },
  created() {
    this.checkListInit();
    this.getDict();
    this.$nextTick(()=>{
    this.searchFunc();
    })
  },
  computed: {
    // 展示字段
    showData() {
      let arr = this.textData.map(v => {
        return v.label;
      });
      let valArr = [],
        showData = [];
      // 选中的字段排序
      arr.forEach(element => {
        let flag = false;
        this.checkList.forEach(e => {
          if (e == element) {
            flag = true;
          }
        });
        if (flag) {
          valArr.push(element);
        }
      });
      // 控制表列隐藏显示
      for (let i = 0; i < this.checkList.length; i++) {
        for (let j = 0; j < this.textData.length; j++) {
          if (this.textData[j].label == valArr[i]) {
            let item = { ...this.textData[j] };
            showData.push(item);
          }
        }
      }
      return showData;
    }
  },
  watch:{
     addOrEdit() {
      // 窗口打开或关闭清除校验结果
      if (this.$refs.saveForm) {
        this.$refs.saveForm.clearValidate();
      }
    },
    isScopeDialog(){
      if(this.$refs.saveFormInner){
        this.$refs.saveFormInner.clearValidate();
    }
    }
  },
  mounted() {
  },
  methods: {
    checkListInit() {
      this.checkList = this.textData.map(v => v.label);
    },
  getDict(){
    systemManage.queryAllEnableModules().then(res => {
        if (res && res.code == 200) {
          this.moduleList = res.datas;
        }
      });
  },
    // 编号是否重复校验
    caliberProjectCodeValid(rule, value, callback) {
      // 只在新增时校验
      if (this.saveFlg != 1) {
        callback();
        return;
      }
      publicManage_pub
        .caliberMemberCheckDefCode({ caliberProjectCode: value })
        .then(res => {
          if (res.code==200) {
            callback();
            } else {
            callback(new Error("编号已存在"));
          }
        });
    },
    caliberCodeValid(rule, value, callback){
      // 只在新增时校验
      if (this.saveFlgInner != 1) {
        callback();
        return;
      }
      publicManage_pub
        .caliberMemberDefCheckDefCode({ caliberProjectCode: this.saveFormInner.caliberProjectCode,caliberCode:value })
        .then(res => {
          if (res.code==200) {
            callback();
            } else {
            callback(new Error("编号已存在"));
          }
        });
    },
    // 点击左侧table获取业务口径规则列表
    rowClickForRule(row) {
      this.$nextTick(()=>{
      this.$refs.definitionTable.clearSelection();
      this.$refs.definitionTable.toggleRowSelection(row);
      })
      this.ruleRow = row;
      this.RTitle = row.caliberName
      this.ruleQueryList()
    },
    // 查询业务口径规则列表
    ruleQueryList(){
      let  data = {
        caliberCode:this.ruleRow.caliberCode,
        caliberProjectCode:this.configRow.caliberProjectCode,
      }
      publicManage_pub.caliberMemberRuleQueryList(data).then(res=>{
        if(res.code==200){
            this.kjRuleTable =  res.data 
        }
      })
    },
    // 查询
    searchFunc(){
        publicManage_pub.caliberMemberQuery(this.searchForm).then(res => {
        if(res.code==200){
          this.tableData = res.data;
          this.total = res.count;
        }
      });
    },
    // 口径定义弹窗表的查询
    searchFFunc(){
      console.log("searchFFunc")
      let data= {
        caliberProjectCode:this.configRow.caliberProjectCode,
        ...this.searchFF
      }
    publicManage_pub.caliberDefQuery(data).then(res => {
        console.log(res, "===");
        this.definitionTableData = res.data;
        this.totalConf = res.count;
        // 如果查出数据右侧默认查第一条
        if(res.data[0]){
          this.rowClickForRule(this.definitionTableData[0])
        }else{
          this.kjRuleTable = []
          this.RTitle = ""
        }
      });
    },
    multipleTableRowClick(row){
      this.$refs.multipleTable.clearSelection();
      this.$refs.multipleTable.toggleRowSelection(row, true);
    },
    addFunc() {
      this.saveFlg = 1;
      for (let k in this.saveForm) {
        this.saveForm[k] = "";
      }
      this.addOrEdit = true;
        this.$nextTick(() => {
        // 清除校验结果
        this.$refs.saveForm.clearValidate();
      });
    },
    editFunc() {
      this.saveFlg = 2;
      let selection = this.$refs.multipleTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据进行修改");
      }
      let row = selection[0];
      let form = {
        caliberProjectCode: row.caliberProjectCode,
        caliberProjectName: row.caliberProjectName,
        moduleCode: row.moduleCode
      };
      this.saveForm = form;
      this.addOrEdit = true;
    },
    saveFunc(){
       this.$refs["saveForm"].validate(valid => {
        if (valid) {
           let data = {
        ...this.saveForm
      };
      publicManage_pub.caliberMemberSave(data).then(res => {
        if (res.code == 200) {
          this.$message.success("保存成功");
          this.addOrEdit = false;
          this.searchFunc();
        }else{
          this.$message.error(res.message||"保存失败")
        }
      });
        }
      });
     
    },
    deleteFunc() {
      let selection = this.$refs.multipleTable.selection;
      if (selection.length < 1) {
        return this.$message.warning("请选择要删除的数据");
      }
      this.$confirm("您确认要删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
            let data = { ids: selection.map(v => v.caliberProjectCode).toString() };
          publicManage_pub.caliberMemberDel(data).then(res => {
            if (res.code == 200) {
              this.$message.success("删除成功");
              this.searchFunc();
            }else{
              this.$message.error(res.message||"删除失败");

            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    configFun() {
      let checked = this.$refs.multipleTable.selection;
      if (checked.length < 1) {
        return this.$message.warning("请选择一条数据");
      } else if (checked.length > 1) {
        return this.$message.warning("只能选择一条数据");
      } else {
        this.isConfigDialog = true;
        this.configRow = checked[0];
        this.searchFFunc();
      }
    },
    // 口径定义表新增
       addFuncInner(){
      
      this.saveFlgInner = 1;
      for (let k in this.saveFormInner) {
        this.saveFormInner[k] = "";
      }
      this.saveFormInner.caliberProjectCode = this.configRow . caliberProjectCode
      this.isScopeDialog = true;
        this.$nextTick(() => {
        // 清除校验结果
        this.$refs.saveFormInner.clearValidate();
      });
    },
    // 口径定义表编辑
    editFuncInner() {
      this.saveFlgInner = 2;
      let selection = this.$refs.definitionTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据进行修改");
      }
      let row = selection[0];
      this.saveFormInner = {...row};
      this.saveFormInner.caliberProjectCode =this.configRow . caliberProjectCode
      this.isScopeDialog = true;
    },
    // 口径定义表保存
    saveFuncInner(){
      
      this.$refs["saveFormInner"].validate(valid => {
        if (valid) {
           let data = {
        ...this.saveFormInner
      };
      publicManage_pub.caliberMemberDefSave(data).then(res => {
        if (res.code == 200) {
          this.$message.success("保存成功");
          this.isScopeDialog = false;
          this.searchFFunc();
        }else{
          this.$message.error(res.message||"保存失败")
        }
      });
        }
      });
    },
    // 口径定义表删除
    deleteFuncInner() {
      let selection = this.$refs.definitionTable.selection;
      if (selection.length < 1) {
        return this.$message.warning("请选择要删除的数据");
      }
      this.$confirm("您确认要删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
         let data = { caliberCodes: selection.map(v => v.caliberCode).toString(),caliberProjectCode:this.configRow.caliberProjectCode};
          publicManage_pub.caliberMemberDefDelete(data).then(res => {
            if (res.code == 200) {
              this.$message.success("删除成功");
              this.searchFFunc();
            }else{
              this.$message.error(res.message||"删除失败");

            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
  //口径定义规则保存
  saveRuleDefFunc(){
    let list = this.ruleDefList
    if(list.length==0)return this.$message.warning('没有数据需要保存')
    let saveValid = {allow:true,text:''};
    let param = {...this.addOrEditRuleRow,
        operateType:this.ruleSaveFlag,
        maxRow :list.length,
        ruleSeq :"",
        ruleAddFlag:"",
        rullValTree:[],
        rullAllVal:[],
        rullValName:[],
        rullVal:[],
        conditionFlag:[],
        dictName:[],
        dictCode:[],
        addFlag:[],
        termSeq:[]
      }

    for (let i = 0; i < list.length; i++) {
      // 非空校验
        if(!list[i].conditionFlag){ saveValid.allow =false;saveValid.text='未选择运算符，请检查';break}
        if(!list[i].rullAllVal){ saveValid.allow =false;saveValid.text='未选择层级方案，请检查';break}
        if(!list[i].rullVal){ saveValid.allow =false;saveValid.text='未选择范围，请检查';break}

        param.termSeq.push(i+1);
        param.addFlag.push(i===0?'':'and');
        param.dictCode.push(list[i].rullDictCode);
        param.dictName.push(list[i].rullDictName );
        param.conditionFlag.push(list[i].conditionFlag );
        param.rullVal.push(list[i].rullVal );
        param.rullValName.push(list[i].rullValName );
        param.rullAllVal.push(list[i].rullAllVal );
        param.rullValTree.push( list[i].rullValTree);
    }
    // 若有空项，打断并提示
    if(!saveValid.allow) return this.$message.warning(saveValid.text)
    for (const k in param) {
      if (param[k]) {
        param[k] = param[k].toString();
      }
    }
    console.log(param,"param")
    publicManage_pub.caliberMemberDimeRuleTermSave(param).then(res=>{
      if(res.code==200){
        this.$message.success("保存成功")
        this.ruleDefShow = false
        this.ruleQueryList()
      }else{
        this.$message.error(res.message||"保存失败")
      }
    })
  },
    // 口径定义规则新增
    addRuleData(){
      if(!this.ruleRow.caliberCode)return this.$message.warning('没有口径可以新增规则')
      this.ruleSaveFlag = 1;
      this.ruleDefList = [];
      this.ruleDefShow = true
      this.addOrEditRuleRow ={
        caliberCode:this.ruleRow.caliberCode,
        caliberProjectCode:this.ruleRow.caliberProject.caliberProjectCode,
        caliberRullCode:""
      }
    },
    // 口径定义规则编辑操作
    editRuleData(row){
      this.ruleSaveFlag = 2;
      console.log(row,"edit")
      let data ={ 
        caliberRullCode:row.caliberRullCode,
        caliberCode:row.caliberCode,
        caliberProjectCode:row.caliberProjectCode}
      this.addOrEditRuleRow = data
      publicManage_pub.caliberMemberRuleTermQueryList(data).then(res=>{
        if(res.code==200){
        this.ruleDefList = res.data;
        this.ruleDefShow = true
        }else{
          this.$message.error(res.message)
        }
      })
    },
    deleteRuleData(row){
      this.$confirm("您确认要删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
         let data = { caliberCode:row.caliberCode,caliberProjectCode:row.caliberProjectCode,caliberRullCode:row.caliberRullCode};
          publicManage_pub.caliberMemberRuleDelete(data).then(res => {
            if (res.code == 200) {
              this.$message.success("删除成功");
              this.searchFFunc();
            }else{
              this.$message.error(res.message||"删除失败");
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
      console.log(row,"delete")
    },
    handleSizeChange(val) {
      this.searchForm.size = val;
      console.log(`每页 ${val} 条`);
      this.searchFunc();
    },
    handleCurrentChange(val) {
      this.searchForm.page = val;
      console.log(`当前页: ${val}`);
      this.searchFunc();
    },
    handleSizeChangeConf(val) {
      this.searchFF.size = val;
      console.log(`每页 ${val} 条`);
      this.searchFFunc();
    },
    handleCurrentChangeConf(val) {
      this.searchFF.page = val;
      console.log(`当前页: ${val}`);
      this.searchFFunc();
    }
  }
};
</script>

<style lang="scss" scoped>
.rowIcon{
  cursor: pointer;
  color:#5F94DF;
  font-size: 16px;
}
// .configWin{
//   /deep/.el-dialog__body{
//     height:500px;
//   }
// }
</style>